package cn.ss.exam2302.util;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.UUID;

// 加密工具类
public class EncryptUtil {
    public static final String ALGORITHM_NAME = Md5Hash.ALGORITHM_NAME;
    public static final int HASH_ITERATIONS = 512;

    // 随机32位字符串
    public static String randUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    // 加密密码
    public static String generatePassword(String source, String salt) {
        SimpleHash simpleHash = new SimpleHash(ALGORITHM_NAME, source, salt, HASH_ITERATIONS);
        return simpleHash.toHex();
    }
}
